﻿/*
 * @Description:编辑楼盘页面js
 * @Author:yangpl
 * @Date:2014-08-19
 */

var pageNewEditEstate = {};

pageNewEditEstate.SetName = function () {
    $("#DistrictName").val($("#selAllDistrictData option:selected").text());
    $("#AareaName").val($("#selGeographyRegionData option:selected").text());
}

//楼盘名称判重验证
pageNewEditEstate.checkEstateName = function () {
    var $TempCurrentEleTxtEstateName = $("#editHouseForm").find("#txtEstateName");
    if ($TempCurrentEleTxtEstateName.val() && $TempCurrentEleTxtEstateName.next(".wrong").length > 0) {
        $TempCurrentEleTxtEstateName.removeClass("checkError").next(".wrong").remove();
    }

    var estateName = $TempCurrentEleTxtEstateName.val();
    var districtKeyId = $("#editHouseForm").find("#selAllDistrictData").val();
    var areaKeyId = $("#editHouseForm").find("#selGeographyRegionData").val();
    var boardKeyId = $("#editHouseForm").find("#selBlockRegionData").val();
    var businessAreaKeyId = $("#editHouseForm").find("#selBusinessAreaData").val();
    var keyId = $("#editHouseForm").find("[name=KeyId]").val();

    if (estateName.length <= 0 || !districtKeyId || !areaKeyId || !boardKeyId || !businessAreaKeyId || !keyId) {
        return false;
    }
    var reqData = {
        "EstateName": estateName,
        "DistrictKeyId": districtKeyId,
        "AreaKeyId": areaKeyId,
        "BoardKeyId": boardKeyId,
        "BusinessAreaKeyId": businessAreaKeyId,
        "KeyId": keyId
    };
    $.AjaxAgency("/estate/check-estate-name", reqData, function (data) {
        if (data == "ok") {
            if ($TempCurrentEleTxtEstateName.next(".wrong").length > 0) {
                $TempCurrentEleTxtEstateName.removeClass("checkError").next(".wrong").remove();
            }
        } else if (data == "no") {
            $TempCurrentEleTxtEstateName.addClass("checkError").after(agencyVerify.greatErrorHtml($TempCurrentEleTxtEstateName, "含有相同名称的楼盘名称"));

        } else {
            $.dialog({
                lock: true,
                background: "#808080",
                opacity: 0.87,
                content: data,
                cancel: function () { }
            });
        }
    });
};

pageNewEditEstate.init = function () {
    var option = {
        titleID: "titleid",
        contentID: "contentdiv",
        currentClassName: "current",
        titleFun: pageNewEditEstate.getTitles,
        urlFun: pageNewEditEstate.getTabUrl,
        dataFun: pageNewEditEstate.getData,
        contentFun: null
    };
    tabHelper(option);
};

pageNewEditEstate.getTitles = function () {
    return $("#hidGetTempOption").val().split(",");
};

pageNewEditEstate.getTabUrl = function (tabname) {
    var urlNum = window.location.href.split('=')[1];
    if (tabname == "基本信息") {

        return "/estate/find-estate-for-edit?KeyId=" + urlNum;
    }
    if (tabname == "重要信息") {
        return "/estate/find-estate-for-edit-importance?KeyId=" + urlNum;
    }
    //if (tabname == "周边设施") {
    //    return "/estate/find-estate-around-for-edit-new?KeyId=" + urlNum;
    //}
    if (tabname == "小区图片") {
        return "/estate/find-estate-photo-for-edit?KeyId=" + urlNum;
    }
    if (tabname == "不具备任何编辑权限") {
        return "/estate/estate-error?errormsg=" + escape("不具备任何编辑权限如有需求请联系管理员");
    }
};

pageNewEditEstate.getData = function (tabname) {
    if (tabname != "栋座") {
        return null;
    } else {
        return [{ name: "key", value: tabname }];
    }
};

//获取片区，板块，商圈数据 sLoadBlock是否加载板块, isLoadRegion是否加载地理片区
pageNewEditEstate.getEstateLinkData = function (isChange, isLoadBlock, isLoadRegion) {
    $("#selBusinessAreaData").html("");
    //只有在加载板块的时候才重置
    if (isLoadBlock) {
        $("#selBlockRegionData").html("");
    }
    if (isLoadRegion) {
        $("#selGeographyRegionData").html("");
    }
    if (!isChange) {
        $("#selAllDistrictData").val($("#selAllDistrictData").attr("bandingsel"));
        $("#selAllCentaNetDistrictData").val($("#selAllCentaNetDistrictData").attr("bandingsel"));
    }
    var tempAllDistrict = $("#selAllDistrictData").val();
    var centaNetDistrict = $("#selAllCentaNetDistrictData").val();
    if (centaNetDistrict == "" || centaNetDistrict == null) {
        centaNetDistrict = "00000000-0000-0000-0000-000000000000";
    }
    if (tempAllDistrict.length < 10) {
        return;
    }
    var reqData = {
        "DistrictKeyId": tempAllDistrict,
        "CentaNetDistrictKeyId": centaNetDistrict
    };
    $.AjaxAgency("/estate/get-create-estate-link-data", reqData, function (data) {
        if (typeof data == "object") {
            //是都重新加载板块数据
            if (isLoadBlock) {
                if (data.BlockRegion.Flag) {
                    var tempHtml = "<option value=''>请选择</option>";
                    for (var i = 0; i < data.BlockRegion.Result.length; i++) {
                        tempHtml += '<option value="' + data.BlockRegion.Result[i].KeyId + '">' + data.BlockRegion.Result[i].RegionName + '</option>';
                    }
                    $("#selBlockRegionData").append(tempHtml);
                    if (!isChange) {
                        $("#selBlockRegionData").val($("#selBlockRegionData").attr("bandingsel"));
                    }
                    // $("#selBlockRegionData").change();
                }
            }
            if (isLoadRegion) {
                if (data.GeographyRegion.Flag) {
                    var tempHtml = "";
                    for (var i = 0; i < data.GeographyRegion.Result.length; i++) {
                        tempHtml += '<option value="' + data.GeographyRegion.Result[i].KeyId + '">' + data.GeographyRegion.Result[i].RegionName + '</option>';
                    }
                    $("#selGeographyRegionData").append(tempHtml);
                    if (!isChange) {
                        $("#selGeographyRegionData").val($("#selGeographyRegionData").attr("bandingsel"));
                    }
                }
            }

            if (data.BusinessArea.Flag) {
                var tempHtml = "";
                for (var i = 0; i < data.BusinessArea.Result.length; i++) {
                    tempHtml += '<option value="' + data.BusinessArea.Result[i].KeyId + '">' + data.BusinessArea.Result[i].RegionName + '</option>';
                }
                $("#selBusinessAreaData").append(tempHtml);
                if (!isChange) {
                    $("#selBusinessAreaData").val($("#selBusinessAreaData").attr("bandingsel"));
                }
            }
            pageNewEditEstate.checkEstateName();
        }
    });
};

//城区类型初始化
pageNewEditEstate.getEstateDistrictTypeData = function (isChange) {
    $("#selDistrictTypeData").html('');
    if (!isChange) {
        $("#selAllDistrictData").val($("#selAllDistrictData").attr("bandingsel"));
    }
    var tempAllDistrict = $("#selAllDistrictData").val();
    //if (!($.trim(tempAllDistrict).length >0) || tempAllDistrict == "-1") return;
    if (tempAllDistrict.length < 10) { return; }
    var reqData = { "DistrictKeyIdAll": tempAllDistrict };
    //$("#selDistrictTypeData").html('<option value="-1">-请选择-</option>');
    $.AjaxAgency("/estate/est-dis-districttype-json", reqData, function (res) {
        if (res.Flag) {
            var data = res.Result;
            var tempHtml = "", tempCount = 0;
            for (var i = 0; i < data.length; i++) {
                tempHtml += '<option value="' + data[i].DistrictTypeKeyId + '">' + data[i].DistrictTypeName + '</option>';
            }
            $("#selDistrictTypeData").append(tempHtml);
            if (!isChange) {
                $("#selDistrictTypeData").val($("#selDistrictTypeData").attr("bandingsel"));
            }
        }
    });
}

//获取大楼盘
pageNewEditEstate.getBigHouseData = function () {
    $("#selBigHouseData").html("");
    var tempKeyId = $("#selBlockRegionData").val();
    if (!tempKeyId || tempKeyId.length < 10) {
        return;
    }
    var reqData = {
        "EstateTagTypeCode": "20",
        "DistrictKeyId": $("#selAllDistrictData").val(),
        "RegionKeyId": tempKeyId
    };
    $.AjaxAgency("/estate/get-bighouse-bydis-reg", reqData, function (data) {
        if (typeof data == "object") {
            var tempHtml = '<option value="-1">请选择</option>';
            for (var i = 0; i < data.length; i++) {
                tempHtml += '<option value="' + data[i].KeyId + '">' + data[i].EstateTagName + '</option>';
            }
            $("#selBigHouseData").append(tempHtml);
            $("#selBigHouseData").val($("#selBigHouseData").attr("bandingsel"));

        } else if (data == "ok") {

        } else {
            $.dialog({
                lock: true,
                background: "#808080",
                opacity: 0.87,
                content: data,
                cancel: function () { }
            });
        }
    });
};

pageNewEditEstate.getDwellingSubType = function (isChange) {
    $("#selDwellingSubType").html("");
    if (!isChange) {
        $("#selDwellingType").val($("#selDwellingType").attr("bandingsel"));
    }
    var tempKeyId = $("#selDwellingType").val();
    if (!tempKeyId || tempKeyId.length < 10) {
        return;
    }
    var reqData = {
        "KeyId": $("#selDwellingType").val()
    };
    $.AjaxAgency("/estate/find-sys-parameter-dwellingsubtype", reqData, function (data) {
        if (typeof data == "object") {
            var tempHtml = '<option value="-1">请选择</option>';
            for (var i = 0; i < data.length; i++) {
                tempHtml += '<option value="' + data[i].ItemValue + '">' + data[i].ItemText + '</option>';
            }
            $("#selDwellingSubType").append(tempHtml);
            if (!isChange) {
                $("#selDwellingSubType").val($("#selDwellingSubType").attr("bandingsel"));
            }
            $("#selDwellingSubType").change();

        } else if (data == "ok") {

        } else {
            $.dialog({
                lock: true,
                background: "#808080",
                opacity: 0.87,
                content: data,
                cancel: function () { }
            });
        }
    });
};

pageNewEditEstate.onBegin = function () {
    other.buttonDisable("#btnSubEditData", "disabled");
};

pageNewEditEstate.success = function (data) {
    other.buttonStart("#btnSubEditData", "disabled");
    if (data == "ok") {
        $.dialog({
            lock: true,
            id: "aa",
            background: "#808080",
            opacity: 0.87,
            content: "编辑成功！"
        });
        setTimeout("art.dialog({ id: 'aa' }).close()", 1500)
    } else {
        $.dialog({
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: data
        });
    }

};

//基本信息页面初始化
pageNewEditEstate.getEditEstateBaseInfoInit = function () {

    $.inputStatistics("txtEditRemark", 200);
    $.inputStatistics("txtVillageSituation", 500);
    $.inputStatistics("txtPeripheryMatching", 500);
    ////初始化片区，板块，商圈数据 
    //pageNewEditEstate.getEstateLinkData();
    //pageNewEditEstate.getEstateDistrictTypeData();
    //pageNewEditEstate.getDwellingSubType(false);
    //$("#selAllDistrictData").change(function () {
    //    pageNewEditEstate.getEstateLinkData(true);
    //    pageNewEditEstate.getEstateDistrictTypeData(true);
    //});

    //$("#selDwellingType").change(function () {
    //    pageNewEditEstate.getDwellingSubType(true);
    //});

    $("#selBlockRegionData").change(function () { pageNewEditEstate.getBigHouseData(); });
    var tempPropertyUsageData = dataBind.getRealDataByType(3), tempPropertyRightNatureKeyIdData = dataBind.getRealDataByType(53), tempPropertyTypeData = dataBind.getRealDataByType(4);

    $("#selPropertyRightNatureKeyId").append('<option value="-1">--请选择--</option>');
    for (var j = 0; j < tempPropertyRightNatureKeyIdData.length; j++) {
        $("#selPropertyRightNatureKeyId").append('<option value="' + tempPropertyRightNatureKeyIdData[j].ItemValue + '">' + tempPropertyRightNatureKeyIdData[j].ItemText + '</option>');

    }
    $("#selPropertyRightNatureKeyId").val($("#selPropertyRightNatureKeyId").attr("bandingsel"));

    //for (var i = 0; i < tempPropertyUsageData.length; i++) {
    //    $("#selPropertyUsageData").append('<option value="' + tempPropertyUsageData[i].ItemValue + '">' + tempPropertyUsageData[i].ItemText + '</option>');
    //}
    //$("#selPropertyUsageData").val($("#selPropertyUsageData").attr("bandingsel"));
    for (var i = 0; i < tempPropertyTypeData.length; i++) {
        $("#selPropertyTypeData").append('<option value="' + tempPropertyTypeData[i].ItemValue + '">' + tempPropertyTypeData[i].ItemText + '</option>');
    }

    $("#selPropertyTypeData").val($("#selPropertyTypeData").attr("bindingsel"));
    $("#selRoomNoRuleData").val($("#selRoomNoRuleData").attr("bandingsel"));
    $("#selEstateTypeKeyId").val($("#selEstateTypeKeyId").attr("bandingsel"));
    $("#selStairType").val($("#selStairType").attr("bindvalue"));
    $("#divSubwayBox select.selSubwayStationKeyId,#divSubwayBox select.selSubwayKeyId").each(function (i, e) { $(e).val($(e).attr("bandingsel")); });
};

pageNewEditEstate.getEditEstateImportanceInit = function () {
    //勾选是否官网显示需要验证官网行政区和板块死活必填项
    $("#editHouseForm input[name=IsWebSiteDisplay]").click(function () {
        if ($(this).attr("checked") == "checked") {
            $("#selAllCentaNetDistrictData").attr('notnull', '1');
            $("#selBlockRegionData").attr('notnull', '1');
        }
        else {
            $("#selAllCentaNetDistrictData").removeAttr('notnull');
            //移除必填项的样式
            if ($("#selAllCentaNetDistrictData").next(".wrong").length > 0) {
                $("#selAllCentaNetDistrictData").removeClass("checkError").next(".wrong").remove();
            }
            $("#selBlockRegionData").removeAttr('notnull');
            if ($("#selBlockRegionData").next(".wrong").length > 0) {
                $("#selBlockRegionData").removeClass("checkError").next(".wrong").remove();
            }
        }
    });
    //初始化片区，板块，商圈数据 
    pageNewEditEstate.getEstateLinkData(false, true, true);
    pageNewEditEstate.getEstateDistrictTypeData();
    pageNewEditEstate.getDwellingSubType(false);
    //官网行政区联动板块
    $("#selAllCentaNetDistrictData").change(function () {
        pageNewEditEstate.getEstateLinkData(true, true, false);
    });
    //A+行政区联动行政区类型和地址片区数据
    $("#selAllDistrictData").change(function () {
        pageNewEditEstate.getEstateLinkData(true, false, true);
        pageNewEditEstate.getEstateDistrictTypeData(true);
    });

    $("#selDwellingType").change(function () {
        pageNewEditEstate.getDwellingSubType(true);
    });

    var tempPropertyUsageData = dataBind.getRealDataByType(3), tempPropertyTypeData = dataBind.getRealDataByType(4);
    for (var i = 0; i < tempPropertyUsageData.length; i++) {
        $("#selPropertyUsageData").append('<option value="' + tempPropertyUsageData[i].ItemValue + '">' + tempPropertyUsageData[i].ItemText + '</option>');
    }
    $("#selPropertyUsageData").val($("#selPropertyUsageData").attr("bandingsel"));


    $("#selRoomNoRuleData").val($("#selRoomNoRuleData").attr("bandingsel"));
}


//周边设施页面初始化
pageNewEditEstate.getEditEstateAroundInit = function () {
    //如果有锁的权限下判断操作锁按钮
    $("#chbIsLockEstateAround").click(function () {
        if ($(this).attr("checked") == undefined) {
            $("#emShowDiv").removeClass("mask2");
        } else {
            $("#emShowDiv").addClass("mask2");
        }
    });
    //初始化多选文本框显示值
    $(".multipleDiv").each(function () {
        var checkedName = [];
        var $checked = $(this).find(":checked");
        if ($checked.length > 0) {
            $checked.each(function () {
                checkedName[checkedName.length] = $(this).attr("text");
            });
        }
        $(this).prev().find(".multipleTxt").val(checkedName.join(","));
    });

    //多选文本框事件
    $(".multipleTxt").unbind("click");
    $(".multipleTxt").bind("click", function () {
        var multipleDiv = $(this).parent().next(".multipleDiv");
        $(".multipleTxt").parent().next(".multipleDiv").not(multipleDiv).hide();
        if (multipleDiv.find(":checkbox").length > 0) {
            multipleDiv.show();
        }

        $(document).unbind("click", pageNewEditEstate.hideMultipleDiv);
        $(document).bind("click", multipleDiv, pageNewEditEstate.hideMultipleDiv);

        return false;
    });

    //多选下拉框checkbox事件
    $(".multipleDiv :checkbox").unbind("click");
    $(".multipleDiv :checkbox").bind("click", function () {
        var checkedName = [];
        var multipleDiv = $(this).parents(".multipleDiv")[0];
        var $checked = $(multipleDiv).find(":checked");
        if ($checked.length > 0) {
            $checked.each(function () {
                checkedName[checkedName.length] = $(this).attr("text");
            });
        }
        $(multipleDiv).prev().find(".multipleTxt").val(checkedName.join(","));
    });
};

pageNewEditEstate.hideMultipleDiv = function (event) {
    var tempoint = event.data.offset();
    if (event.pageX > (tempoint.left + event.data.width()) || event.pageX < tempoint.left || event.pageY > (tempoint.top + event.data.height()) || event.pageY < tempoint.top) {
        event.data.hide();
        $(document).unbind("click", pageNewEditEstate.hideMultipleDiv);
    }
};

//栋座搜索智能提示
pageNewEditEstate.searchBuildingAutoMatch = function ($obj, estateKeyId) {
    //栋座搜索智能提示Url
    pageNewEditEstate.getBuildingUrl = function () {
        return "/Estate/auto-match-building-name?EstateKeyId=" + estateKeyId + "&BuildingName=" + escape($obj.val());
    };
    //楼盘自动完成及赋值隐藏域
    $obj.autocomplete(pageNewEditEstate.getBuildingUrl, {
        width: 100,
        max: 1000,
        Default: 1,
        selectFirst: false,
        cacheLength: 0,
        formatItem: function (row) {
            return row.ItemText;
        },
        formatResult: function (row) {
            return row.ItemText;
        }
    }).result(function (a, b) {
        $obj.next().val(b.ItemValue);
        $obj.next().next(".wrong").remove();
        $obj.removeClass("checkError");
    });
    //注册文本框改变事件（处理不选择的时候清空隐藏域KeyId）
    $obj.unbind("change");
    $obj.bind("change", function () {
        $obj.next().val("");
    });
};

//小区图片页面初始化
pageNewEditEstate.getEditEstatePhotoInit = function () {
    //注册加载的栋座图智能提示事件
    $.each($("#dzimgdiv").find(":text[name=BuildingName]"), function () {
        pageNewEditEstate.searchBuildingAutoMatch($(this), $("#hidEstateKeyId").val());
    });
    //保存按钮点击事件
    $(":submit").unbind("click");
    $(":submit").bind("click", function () {
        var hasEmptyKeyId = false;
        $("#dzimgdiv :hidden[name=BuildingKeyId]").each(function () {
            if ($(this).val() == "") {
                hasEmptyKeyId = true;
                if ($(this).next(".wrong").length <= 0) {
                    $(this).after('<span class="wrong" style="position:absolute;left:204px;top:44px;background-position:-15px -372px;">必须从智能提示中选择栋座。</span>');
                    $(this).prev().addClass("checkError");
                }
            }
        });
        if (hasEmptyKeyId) {
            return false;
        }
    });
    //取消实勘图上传 刘道阳
    var settings = {
        flash_url: "/Scripts/PageHelper/swfupload.swf",
        upload_url: $("#uploadPath").val(),
        post_params: {},
        file_size_limit: "2 MB",
        file_types: "*.jpg;*.png",
        file_types_description: "JPG Images",
        file_upload_limit: 100,
        file_queue_limit: 100,
        custom_settings: {
            progressTarget: "fsUploadProgress"
        },
        debug: false,

        // Button settings
        button_image_url: "/static/app/img/btn-local-img.png",
        button_width: "108",
        button_height: "36",
        button_placeholder_id: "uploadEstatePhoto",
        button_cursor: SWFUpload.CURSOR.HAND,
        button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
        button_text: '',
        button_text_style: "",
        button_text_left_padding: 12,
        button_text_top_padding: 3,

        // The event handler functions are defined in handlers.js
        file_queued_handler: fileQueued,
        file_queue_error_handler: fileQueueError,
        file_dialog_complete_handler: fileDialogComplete,
        upload_start_handler: uploadStart,
        upload_progress_handler: uploadProgress,
        upload_error_handler: uploadError,
        upload_success_handler: uploadSuccessEstatePhoto,
        upload_complete_handler: uploadComplete,
        queue_complete_handler: queueComplete	// Queue plugin event
    };
    var swfu = new SWFUpload(settings);

    function uploadSuccessEstatePhoto(file, serverData) {
        try {
            var progress = new FileProgress(file, this.customSettings.progressTarget);
            progress.setComplete();
            progress.setStatus("Complete.");
            progress.toggleCancel(false);

            var $innerhtml = $($("#estatePhotoAddModel").html());
            $innerhtml.find("img").eq(0).attr("src", other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData));
            $innerhtml.find(":hidden[name=EstatePhotoPath]").val(serverData);
            $("#xqimgdiv").append($innerhtml.get(0).outerHTML);
        } catch (ex) {
            this.debug(ex);
        }
    }

    //var settings2 = {
    //    flash_url: "/Scripts/PageHelper/swfupload.swf",
    //    upload_url: $("#uploadPath").val(),
    //    post_params: {},
    //    file_size_limit: "2 MB",
    //    file_types: "*.jpg;*.png",
    //    file_types_description: "JPG Images",
    //    file_upload_limit: 500,
    //    file_queue_limit: 500,
    //    custom_settings: {
    //        progressTarget: "fsUploadProgress"
    //    },
    //    debug: false,

    //    // Button settings
    //    button_image_url: "/static/app/img/btn-local-img.png",
    //    button_width: "108",
    //    button_height: "36",
    //    button_placeholder_id: "uploadBuildingPhoto",
    //    button_cursor: SWFUpload.CURSOR.HAND,
    //    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
    //    button_text: '',
    //    button_text_style: "",
    //    button_text_left_padding: 12,
    //    button_text_top_padding: 3,

    //    // The event handler functions are defined in handlers.js
    //    file_queued_handler: fileQueued,
    //    file_queue_error_handler: fileQueueError,
    //    file_dialog_complete_handler: fileDialogComplete,
    //    upload_start_handler: uploadStart,
    //    upload_progress_handler: uploadProgress,
    //    upload_error_handler: uploadError,
    //    upload_success_handler: uploadSuccessBuildingPhoto,
    //    upload_complete_handler: uploadComplete,
    //    queue_complete_handler: queueComplete	// Queue plugin event
    //};
    //var swfu2 = new SWFUpload(settings2);

    function uploadSuccessBuildingPhoto(file, serverData) {
        try {
            var progress = new FileProgress(file, this.customSettings.progressTarget);
            progress.setComplete();
            progress.setStatus("Complete.");
            progress.toggleCancel(false);

            var $innerhtml = $($("#buildingPhotoAddModel").html());
            $innerhtml.find("img").eq(0).attr("src", other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData));
            $innerhtml.find(":hidden[name=BuildingPhotoPath]").val(serverData);
            $("#dzimgdiv").append($innerhtml.get(0).outerHTML);
            //为刚上传的栋座图注册智能提示
            pageNewEditEstate.searchBuildingAutoMatch($("#dzimgdiv").find(":text[name=BuildingName]").last(), $("#hidEstateKeyId").val());
        } catch (ex) {
            this.debug(ex);
        }
    }

    var settings3 = {
        flash_url: "/Scripts/PageHelper/swfupload.swf",
        upload_url: $("#uploadPath").val(),
        post_params: {},
        file_size_limit: "2 MB",
        file_types: "*.jpg;*.png",
        file_types_description: "JPG Images",
        file_upload_limit: 500,
        file_queue_limit: 500,
        custom_settings: {
            progressTarget: "fsUploadProgress"
        },
        debug: false,

        // Button settings
        button_image_url: "/static/app/img/btn-local-img.png",
        button_width: "108",
        button_height: "36",
        button_placeholder_id: "uploadRoomPhoto",
        button_cursor: SWFUpload.CURSOR.HAND,
        button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
        button_text: '',
        button_text_style: "",
        button_text_left_padding: 12,
        button_text_top_padding: 3,

        // The event handler functions are defined in handlers.js
        file_queued_handler: fileQueued,
        file_queue_error_handler: fileQueueError,
        file_dialog_complete_handler: fileDialogComplete,
        upload_start_handler: uploadStart,
        upload_progress_handler: uploadProgress,
        upload_error_handler: uploadError,
        upload_success_handler: uploadSuccessRoomPhoto,
        upload_complete_handler: uploadComplete,
        queue_complete_handler: queueComplete	// Queue plugin event
    };
    var swfu3 = new SWFUpload(settings3);

    function uploadSuccessRoomPhoto(file, serverData) {
        try {
            var progress = new FileProgress(file, this.customSettings.progressTarget);
            progress.setComplete();
            progress.setStatus("Complete.");
            progress.toggleCancel(false);

            var $innerhtml = $($("#roomPhotoAddModel").html());
            $innerhtml.find("img").eq(0).attr("src", other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData) + "?width=120&height=100&mode=stretch");
            $innerhtml.find(":hidden[name=RoomPhotoPath]").val(serverData);
            $("#hximgdiv").append($innerhtml.get(0).outerHTML);
        } catch (ex) {
            this.debug(ex);
        }
    }
};

//楼盘字典添加小区图地方使用
pageNewEditEstate.removePhoto = function (ele) {
    $.OKCancelDialogAgency('<div class="tc">您确定要删除当前图片吗？</div>', "提示", null, function () {
        $(ele).parents('.up-pic').eq(0).remove();
    });

};
pageNewEditEstate.searchEstateSchoolAutoMatch = function ($obj) {
    $obj.each(function (i, e) {
        //楼盘字典学校搜索地址
        pageNewEditEstate.getEstateSchoolUrl = function () {
            var educationSearchValue = $(e).val();
            var districtKeyId = $("#selAllDistrictData").val();
            return '/Estate/auto-match-school-value?EducationSearchValue=' + escape(educationSearchValue) + '&districtKeyId=' + districtKeyId;
        };

        //楼盘学校地址自动提示
        $(e).autocomplete(pageNewEditEstate.getEstateSchoolUrl, {
            width: 200,
            max: 500,
            Default: 1,
            selectFirst: false,
            cacheLength: 0,
            formatItem: function (row) {
                return row.value;
            },
            formatResult: function (row) {
                return row.value;
            }
        }).change(function () {
            $(this).siblings("input[name='EducationSchoolKeyId']").val("");
        }).result(function (e, b) {
            var tObj = $(this);
            var oObj = tObj.siblings("input[name='EducationSchoolKeyId']");
            if (b.key == "#error") {
                $(this).val("");
            }
            else if (b.key || b.key.length > 0) {
                oObj.attr("value", b.key);
                var sObj = $(this).parent().siblings();
                var isOk = true;
                sObj.each(function (i, exv) {
                    var cObj = $(exv).find("input[name='EducationSchoolKeyId']");
                    if (oObj.val() == cObj.val()) {
                        oObj.attr("value", "");
                        tObj.val("");
                        isOk = false;
                        $.dialog({
                            lock: true,
                            id: "xxx_school",
                            background: "#808080",
                            opacity: 0.87,
                            content: "已存在相同学校！"
                        });
                        setTimeout("art.dialog({ id: 'xxx_school' }).close()", 1500);
                        return false;
                    }
                });
            } else {
                $(this).val("");
            }
        });
    });


    //地铁线路
    pageNewEditEstate.TransportationKeyId = function (obj, selected) /* 当前对象，selected 当前需要选中的值*/ {
        var url = "/estate/est-subway-line-json";
        obj.empty();
        obj.append('<option selected value="-1">请选择线路</option>');
        $.AjaxAgency(url, null, function (data) {
            if (typeof data == "object") {
                for (var i = 0; i < data.length; i++) {
                    if (data[i].KeyId == selected) {
                        obj.append('<option selected value="' + data[i].KeyId + '">' + data[i].TransportationName + '</option>');
                    } else {
                        obj.append('<option value="' + data[i].KeyId + '">' + data[i].TransportationName + '</option>');
                    }
                }
            } else {
                $.OKDialogAgency('<div class="tc">' + data + '</div>');
            }
        });
    }

    //地铁站点
    pageNewEditEstate.TransportationItemKeyId = function (obj, prevObj, selected)/*obj当前下拉框对象，prevObj 上一级联对象，selected 当前默认选中的值*/ {
        var val = prevObj.val();
        obj.empty();
        obj.append('<option selected value="-1">请选择站点</option>');
        if (val && val != "-1" && val.IsGuid()) {
            var url = "/estate/find-station-by-subway";
            var reqData = {
                "TransportationKeyId": val
            };
            $.AjaxAgency(url, reqData, function (data) {
                if (typeof data == "object") {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].KeyId == selected) {
                            obj.append('<option selected value="' + data[i].KeyId + '">' + data[i].TransportationItemName + '</option>');
                        } else {
                            obj.append('<option value="' + data[i].KeyId + '">' + data[i].TransportationItemName + '</option>');
                        }
                    }
                } else {
                    $.OKDialogAgency('<div class="tc">' + data + '</div>');
                }
            });
        }
    }
    pageNewEditEstate.SchoolValid = function (from, dynamic) {
        var schoolInput = "#divSchoolInfoBox .spanEstateSchool input[name='EducationSearchValue']";
        schoolValid = function (e) {
            var obj = $(e.target || e);
            var re = 0;
            obj.each(function (i, eo) {
                var ex = $(eo);
                var vObj = ex.siblings("input[name='EducationSchoolKeyId']:eq(0)");
                var wrongspan = $(ex).next();
                if (vObj.val() != null && !vObj.val().IsGuid()
                    && ex.val() != null && $.trim(ex.val()).length > 0) {
                    if (wrongspan.attr("class") != "wrong") {
                        ex.after(agencyVerify.greatErrorHtml(ex, "请从下拉提示中选择！"));
                        ex.addClass("checkError");
                        re++;
                    } else {
                        re++;
                    }
                } else {
                    if (wrongspan.attr("class") == "wrong") {
                        wrongspan.remove();
                        ex.removeClass('checkError');
                    }
                }
            });
            return re == 0;
        }
        if (dynamic) {
            $(from).on("blur", schoolInput, schoolValid);
        } else {
            $(schoolInput).bind("blur", schoolValid);
        }
        $(from).bind("submit", function () { return schoolValid($(schoolInput)); });
    }
    pageNewEditEstate.SubWayValidRepsInit = function () {
        var subWay = $(".spanSubwayItem select[name='SubwayKeyId']");
        subWay.live("change", cvnxt = function () {
            var obj = $(this);
            var val = obj.val();
            var cObj = obj.parent().parent().find("select[name='SubwayStationKeyId']");
            if (obj.val() == null || $.trim(obj.val()) != "-1") {
                cObj.attr("notnull", "1");
            }
            else {
                cObj.removeAttr("notnull");
                var wrongspan = $(cObj).next();
                if (wrongspan.attr("class") == "wrong") {
                    wrongspan.remove();
                }
            }
        });
        subWay.each(function (i, e) {
            var tObj = $(this);
            //var subWayObj = tObj.parent().parent().find("select[name='SubwayKeyId']");
            var subWayItemObj = tObj.parent().parent().find("select[name='SubwayStationKeyId']");
            if (tObj.val().IsGuid()) {
                subWayItemObj.attr("notnull", "1");
            }
        });
        var subWayItemObj = $(".spanSubwayItem select[name='SubwayStationKeyId']");
        subWayItemObj.live("change", function () {
            var tObj = $(this);
            var pObj = tObj.parent().parent();
            var bObj = pObj.find("select[name='SubwayKeyId']");
            var sObj = pObj.siblings(".spanSubwayItem");
            sObj.each(function (i, e) {
                var bItemObj = $(e).find("select[name='SubwayKeyId']");
                var tItemObj = $(e).find("select[name='SubwayStationKeyId']");
                if (bObj.val() != "-1" && tObj.val() != "-1" && bObj.val() == bItemObj.val() && tObj.val() == tItemObj.val()) {
                    $.dialog({
                        lock: true,
                        id: "xxx_subway",
                        background: "#808080",
                        opacity: 0.87,
                        content: "已存在相同线路、站点！"
                    });
                    setTimeout("art.dialog({ id: 'xxx_subway' }).close()", 1500);
                    tObj.val("-1");
                    return false;
                }
            });
        });
    }
    //失去焦点处理、应对统一出发不同问题处理
    pageNewEditEstate.LoseBlur = function (ref, ef, callback) {  //ref 参考对象 
        $(ref || "body").one("click", function (e) {
            var target = e.target;
            callback(target, ef, target.tagName);
        });
    }
}